package com.ydgk.Test;

import com.ydgk.bean.User;
import com.ydgk.dao.UserDao;
import com.ydgk.service.UserService;
import org.junit.Before;
import org.junit.Test;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

public class UserDaoTest {
    protected UserDao userDao;
    @Before
    public void init(){
        userDao=new UserDao();
    }

    @Test
    public void saveTest(){
        User user = new User();
        user.setUname("123");
        user.setUbrith(new Date(System.currentTimeMillis()));
        user.setUadress("324");
        user.setUpass("123");
        user.setUsex(1);
        user.setUtype(0);
        user.setManage(0);
        System.out.println(userDao.save(user));
    }

    @Test
    public void findAllTest(){
        List<User> all = userDao.findAll();
        for (User user : all) {
            System.out.println(user);
        }
    }

    @Test
    public void updateMoneyTest(){
        User user = userDao.findById(1);
        System.out.println(userDao.updateMoneyById(user,1));
    }

    @Test
    public void pagingTest(){
        List<User> paging = userDao.paging(1);
        for (User user : paging) {
            System.out.println(user);
        }
    }

    @Test
    public void updateById(){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        User user = new User();
        user.setUid(37);
        user.setUname("ddd");
        user.setUtype(1);
        user.setUadress("亚洲");
        user.setUphone(123333);
        UserDao userDao = new UserDao();
        System.out.println(userDao.updateById(user));
    }

}
